package multimanipulators;

	import java.io.File;
import java.io.FileNotFoundException;
	import java.io.FileOutputStream;
	import java.io.IOException;
	import java.io.InputStream;
import java.io.OutputStream;

	import java.io.OutputStreamWriter;
	import java.io.RandomAccessFile;
	import java.io.UnsupportedEncodingException;
	import java.nio.channels.Channels;
	import java.nio.channels.FileChannel;
	import java.util.ArrayList;



	import multimanipulators.converters.simple.Converter_delete;
	import multimanipulators.converters.simple.Converter_replaceString;

	import multimanipulators.finders.Finder;

import multimanipulators.interfaces.Finders;
import multimanipulators.interfaces.StreamManipulators;
	/**
	 * @author Lieven Roegiers
	 * @copyright 2010
	 * @project javamylibs
	 * @from http://javamylibs.googlecode.com/svn/trunk/
	 * 
	 * clean code remove emty lines make codefile small and maximal view
	**/
	public class Codecleaner {
		private static boolean Debug = false;
		private static StreamManipulators x;

		public static void main(String[] args) {
			System.out.println("<<<START>>>");        
			try {
	        	ArrayList<Finders> y = new ArrayList<Finders>();
	        	y.add(new Finder(new String(")\r\n{"),new Converter_replaceString("){")));
	        	y.add(new Finder(new String(") \r\n{"),new Converter_replaceString("){")));
	        	y.add(new Finder(") \n{",new Converter_replaceString("){")));       	
	        	y.add(new Finder(") \r\n\t{",new Converter_replaceString("){")));
	        	y.add(new Finder(")\r\n	{",new Converter_replaceString("){")));
	        	y.add(new Finder(")\n	{",new Converter_replaceString("){")));
	        	y.add(new Finder(")/s\r\n\t{",new Converter_replaceString("){")));
	        	y.add(new Finder(")\r\t{",new Converter_replaceString("){")));        	
	        	y.add(new Finder(")\r	{",new Converter_replaceString("){")));
	        	y.add(new Finder("\r\n	{",new Converter_replaceString("{")));
	        	y.add(new Finder("\r\n		{",new Converter_replaceString("{")));
	        	y.add(new Finder("\r\n			{",new Converter_replaceString("{")));
	        	y.add(new Finder("\r\n				{",new Converter_replaceString("{")));
	        	y.add(new Finder("\r\n					{",new Converter_replaceString("{")));
	        	y.add(new Finder("\r\n						{",new Converter_replaceString("{")));
	        	y.add(new Finder(")\r	{",new Converter_replaceString("else")));
	        	y.add(new Finder("\r\n	else",new Converter_replaceString("else")));
	        	y.add(new Finder("\r\n		else",new Converter_replaceString("else")));
	        	y.add(new Finder("\r\n			else",new Converter_replaceString("else")));
	        	y.add(new Finder("\r\n				else",new Converter_replaceString("else")));
	        	y.add(new Finder("\r\n					else",new Converter_replaceString("else")));
	        	y.add(new Finder("\r\n						else",new Converter_replaceString("else")));
	        	y.add(new Finder("\n\n	{",new Converter_replaceString("){")));
	        	y.add(new Finder(")\n\t\t{",new Converter_replaceString("){")));
	        	y.add(new Finder(")\r\n\t\t{",new Converter_replaceString("){")));//2tabs and linebreak
	        	y.add(new Finder(")\n\t\t{",new Converter_replaceString("){")));//2tabs and linebreak
	        	y.add(new Finder(")\r\n\t\t\t{",new Converter_replaceString("){")));//3tabs and linebreak
	        	y.add(new Finder(")\r\n\t\t\t\t{",new Converter_replaceString("){")));//4tabs and linebreak
	        	y.add(new Finder("do\r\n{",new Converter_replaceString("do{")));
	        	y.add(new Finder("do\r\n\t{",new Converter_replaceString("do{")));
	        	y.add(new Finder("do\r\n\t\t{",new Converter_replaceString("do{")));//2tabs and linebreak
	        	y.add(new Finder("do\r\n\t\t\t{",new Converter_replaceString("do{")));//3tabs and linebreak
	        	y.add(new Finder("do\r\n\t\t\t\t{",new Converter_replaceString("do{")));//4tabs and linebreak
	        	y.add(new Finder("}\r\nwhile",new Converter_replaceString("}while")));
	        	y.add(new Finder("}\r\n\twhile",new Converter_replaceString("}while")));
	        	y.add(new Finder("}\r\n\t\twhile",new Converter_replaceString("}while")));//2tabs and linebreak
	        	y.add(new Finder("}\r\n\t\t\twhile",new Converter_replaceString("}while")));//3tabs and linebreak
	        	y.add(new Finder("}\r\n\t\t\t\twhile",new Converter_replaceString("}while")));//4tabs and linebreak
	        	y.add(new Finder(")\r\n\r\n{",new Converter_replaceString("){")));
	        	y.add(new Finder(new String("}\r\nelse\r\n{"),new Converter_replaceString("}else{")));// linebreaks
	        	y.add(new Finder(new String("}\r\n\telse\r\n\t{"),new Converter_replaceString("}else{")));//1tabs and linebreaks
	        	y.add(new Finder(new String("\r\n		 else\r\n\t\t{"),new Converter_replaceString("else{")));//2tabs and linebreaks
	        	y.add(new Finder("\r\n\t\telse",new Converter_replaceString("else")));//2tabs and linebreaks
	        	y.add(new Finder("} \r\n		else\r\n\\t\t{",new Converter_replaceString("}else{")));//2tabs and linebreaks
	        	y.add(new Finder(new String("}\r\n\t\t\telse\r\n\t\t\t{"),new Converter_replaceString("}else{")));//3 tabs and linebreaks
	        	y.add(new Finder(new String("}\r\nelse\r\n{"),new Converter_replaceString("}else{")));
	        	y.add(new Finder("else\r\n{",new Converter_replaceString("else{")));
	        	y.add(new Finder("\r\n \r\n",new Converter_replaceString(" ")));
	        	y.add(new Finder("\r\n\r\n",new Converter_replaceString("\r\n")));
	        	y.add(new Finder("\r\n*\r\n",new Converter_replaceString("\r\n")));
	        	y.add(new Finder("return true;",new Converter_replaceString("return true;//TODO clean return msg")));
	        	y.add(new Finder("return false;",new Converter_replaceString("return false;//TODO clean return msg")));
   
	        	File dest = new File("E:/_A_servers/xampp/htdocs/automaticsitev2.6/intersante scripts/test2.tuned.php");
	            
				File source = new File("E:/_A_servers/xampp/htdocs/automaticsitev2.6/intersante scripts/test2.php");
				//File source = new File("E:/workspace/JAVA_mylibs/presrc/pretest.dat");
			      String encoding = "UTF8";

			      OutputStreamWriter writer = new OutputStreamWriter(
			      new FileOutputStream(dest), encoding);
				FileChannel channel = new RandomAccessFile(source, "rw").getChannel(); 
	            InputStream is = Channels.newInputStream(channel);
	            x = new StreamMultiManipulatorCR1(10,DEBUGMODE.NORMAL);
	            x.findAndReplace(is,y,writer);
			    writer.flush();
			    //writer.write("//tuned by Roegiers L 80072631165");
			    //writer.flush();
	       }catch (UnsupportedEncodingException e) {
	            e.printStackTrace();
	       }catch (FileNotFoundException e) {
	    	   System.out.println("file not exist or is opened by other program"); 
	       }catch (IOException e) {
	    	    e.printStackTrace();
	       }
	       System.out.println("\n<<<STOP:TEST>>>");           
		}

}
